<?php
namespace Functions\Controller;
use Admin\Controller\AdminController;
/**
 * 套系类型
 */

class StyleController extends AdminController {
    /**
     * 当前模块参数
     */
    protected function _infoModule(){
        return array(
            'info'  => array(
                'name' => '套系类型',
                'description' => '管理套系类型',
                ),
            'menu' => array(
                array('name' => '套系类型列表',
                    'url' => U('Functions/Style/index'),
                    'icon' => 'list',
                    ),
                ),
            'add' => array(
                array('name' => '添加套系类型',
                    'url' => U('add'),
                    ),
                ),
            );
    }
	/**
     * 套系类型
     */
    public function index(){
        $breadCrumb = array('套系类型列表' => U());
        $this->assign('breadCrumb', $breadCrumb);
        $map['B.service_status'] = array('eq',1);
        $model = D('Functions/Style');
        //URL参数
        $pageMaps = array();
        //查询数据
        $count = $model->countList($map);
        $limit = $this->getPageLimit($count,10);
        $styleList = $model -> loadList($map,$limit);
        $this->assign('styleList', $styleList);
        $this->assign('page',$this->getPageShow($pageMaps));
        $this->adminDisplay();
    }

    /**
     * 增加
     */
    public function add()
    {
        if (!IS_POST)
        {
            $breadCrumb = array('套系类型' => U('index'), '套系类型添加' => U());
            $this->assign('breadCrumb', $breadCrumb);
            $model = D('Functions/Service');
            $serviceList = $model ->loadList();
            $this->assign('serviceList', $serviceList);
            $this->assign('name', '添加');
            $this->adminDisplay('info');
        }
        else
        {
            $model = D('Functions/Style');

            if ($model->saveData('add'))
            {
                $this->success('套系类型添加成功！');
            }
            else
            {
                $msg = $model->getError();
                if (empty($msg))
                {
                    $this->error('套系类型添加失败');
                }
                else
                {
                    $this->error($msg);
                }
            }
        }
    }

    /**
     * 修改
     */
    public function edit()
    {
        $model = D('Functions/Style');
        if (!IS_POST)
        {
            $styleId = I('get.style_id', '', 'intval');
            if (empty($styleId))
            {
                $this->error('参数不能为空！');
            }
            $info = $model->getInfo($styleId);
            if (!$info)
            {
                $this->error($model->getError());
            }
            $breadCrumb = array('套系类型列表' => U('index'), '服务类型修改' => U('edit', array('fieldset_id' => $fieldsetId)));
            $this->assign('breadCrumb', $breadCrumb);
            $model = D('Functions/Service');
            $serviceList = $model ->loadList();
            $this->assign('serviceList', $serviceList);
            $this->assign('name', '修改');
            $this->assign('info', $info);
            $this->adminDisplay('info');
        }
        else
        {

            if ($model->saveData('edit'))
            {
                $this->success('套系类型修改成功！');
            }
            else
            {
                $msg = $model->getError();
                if (empty($msg))
                {
                    $this->error('服务类型修改失败');
                }
                else
                {
                    $this->error($msg);
                }
            }
        }
    }

  /**
     * 删除
     */
    public function del()
    {
        $styleId = I('post.data');
        if (empty($styleId))
        {
            $this->error('参数不能为空！');
        } 
        // 删除操作
        $model = D('Functions/Style');
        if ($model->delData($styleId))
        {
            $this->success('套系类型删除成功！');
        }
        else
        {
            $msg = $model->getError();
            if (empty($msg))
            {
                $this->error('套系类型删除失败！');
            }
            else
            {
                $this->error($msg);
            }
        }
    }

}

